package servlet;

import data.QueryRecordData;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "QueryServlet")
public class QueryServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setHeader("Content-Type", "text/html");
        response.setCharacterEncoding("UTF-8");
        String start = request.getParameter("start");
        String end = request.getParameter("end");
        String operator = request.getParameter("operator");
        int table = Integer.parseInt(request.getParameter("table"));
        int pageNumber = Integer.parseInt(request.getParameter("pageNumber"));
        int pageSize = Integer.parseInt(request.getParameter("pageSize"));
        String responseText = ""; //返回的数据
        QueryRecordData queryRecordData = new QueryRecordData(start, end, operator, pageNumber, pageSize);
        switch (table) {
            case 1://加密
                responseText = queryRecordData.queryEncryptionData();
                break;
            case 2://解密
                responseText = queryRecordData.queryDecryptionData();
                break;
            case 3://验证
                responseText = queryRecordData.queryVerificationData();
                break;
            case 4://签名
                responseText = queryRecordData.querySignatureData();
                break;
            case 5://签密
                responseText = queryRecordData.querySigncryptionData();
                break;
            case 6://解签密
                responseText = queryRecordData.queryUnsigncryptionData();
                break;
            case 7://MAC
                responseText = queryRecordData.queryMacData();
                break;
            case 8://认证加密
                responseText = queryRecordData.queryAuthenticatedEncryptionData();
                break;
            case 9://解密验证
                responseText = queryRecordData.queryDecryptionVerificationData();
                break;
            default:
        }
        PrintWriter printWriter = response.getWriter();
        printWriter.print(responseText);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        doPost(request, response);
    }
}
